package com.itttq.kb.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.itttq.kb.model.to.PageParamTo;
import com.itttq.kb.model.po.TopicReplyPo;
import com.itttq.kb.mapper.ITopicReplyMapper;

@Service
public class TopicReplyService {
	@Autowired
	private ITopicReplyMapper topicReplyMapper;
	/**
	 * 更新点赞数
	 * 
	 * @param id	回复ID
	 * @return
	 * @Author 迷蝶
	 * @return int
	 */
	public int updateNumberLover(int id) {
		return topicReplyMapper.updateNumber("love", id);
	}
	/**
	 * 估计主题ID删除旗下所有回复
	 * 
	 * @param id	主题ID
	 * @return
	 * @Author 迷蝶
	 * @return int
	 */
	public int delTopicReplyByTid(int tid) {
		return topicReplyMapper.delTopicReplyByTid(tid);
	}
	
	public TopicReplyPo getTopicReply(int id) {
		TopicReplyPo topicReply = new TopicReplyPo();
		topicReply.setId(id);
		return topicReplyMapper.findById(topicReply);
	}

	public List<TopicReplyPo> getTopicReplys(int topicId, PageParamTo ppt) {
		return topicReplyMapper.getTopicReplies(topicId, ppt.getStart(), ppt.getSize());
	}
	
	public List<TopicReplyPo> getTopicReplys(TopicReplyPo topicReply, PageParamTo ppt) {
		return topicReplyMapper.find4page(topicReply, ppt);
	}

	public int getTopicReplyCount(TopicReplyPo topicReply) {
		return topicReplyMapper.getCount(topicReply);
	}

	public void delTopicReply(int id) {
		TopicReplyPo topicReply = new TopicReplyPo();
		topicReply.setId(id);
		topicReplyMapper.delete(topicReply);
	}

	public void addTopicReply(TopicReplyPo topicReply) {
		topicReplyMapper.insert(topicReply);
	}
	
	public void updateTopicReply(TopicReplyPo topicReply) {
		topicReplyMapper.update(topicReply);
	}
}
